using CfgTable;
using IQIGame.Onigao.Framework;
using IQIGame.Onigao.Game;

namespace IQIGame.Onigao.GamePlay
{
    public class UIN_MallRechargeCell : UIBaseNode
    {
        #region Template Generate,don't modify
        protected class UIB_UIN_MallRechargeCell
        {
            #region ObjectBinding Generate
            public UnityEngine.GameObject first { protected set; get; }
            public IQIGame.Onigao.Framework.ExImage iconFirst { protected set; get; }
            public IQIGame.Onigao.Framework.ExText textFirstValue { protected set; get; }
            public IQIGame.Onigao.Framework.ExRawImage rawIcon { protected set; get; }
            public IQIGame.Onigao.Framework.ExText textName { protected set; get; }
            public IQIGame.Onigao.Framework.ExText textDesc { protected set; get; }
            public IQIGame.Onigao.Framework.ExText textPriceValue { protected set; get; }
            public IQIGame.Onigao.Framework.ExText textPriceTitle { protected set; get; }
            public virtual void InitBinding(ObjectBinding __binding)
            {
                __binding.TryGetVariableValue<UnityEngine.GameObject>("first", out var __tbv0);
                this.first = __tbv0;
                __binding.TryGetVariableValue<IQIGame.Onigao.Framework.ExImage>("iconFirst", out var __tbv1);
                this.iconFirst = __tbv1;
                __binding.TryGetVariableValue<IQIGame.Onigao.Framework.ExText>("textFirstValue", out var __tbv2);
                this.textFirstValue = __tbv2;
                __binding.TryGetVariableValue<IQIGame.Onigao.Framework.ExRawImage>("rawIcon", out var __tbv3);
                this.rawIcon = __tbv3;
                __binding.TryGetVariableValue<IQIGame.Onigao.Framework.ExText>("textName", out var __tbv4);
                this.textName = __tbv4;
                __binding.TryGetVariableValue<IQIGame.Onigao.Framework.ExText>("textDesc", out var __tbv5);
                this.textDesc = __tbv5;
                __binding.TryGetVariableValue<IQIGame.Onigao.Framework.ExText>("textPriceValue", out var __tbv6);
                this.textPriceValue = __tbv6;
                __binding.TryGetVariableValue<IQIGame.Onigao.Framework.ExText>("textPriceTitle", out var __tbv7);
                this.textPriceTitle = __tbv7;
            }
            #endregion ObjectBinding Generate 
        }
        #endregion Template Generate,don't modify

        #region fields

        #endregion fields

        #region properties
        protected UIB_UIN_MallRechargeCell ui { get; set; }
        protected UIMsgDispatcher uiMsgDispatcher => this._msgDispatcher as UIMsgDispatcher;

        public int mallItemCid { get; private set; }
        public CfgMallItem CfgMallItem { get; private set; }
        #endregion properties

        protected override void BeforeInit()
        {
            ui = new UIB_UIN_MallRechargeCell();
            ui.InitBinding(this.csObjBind);
        }

        protected override void OnInit()
        {
        }

        protected override void OnShow()
        {

        }

        protected override void OnHide()
        {

        }

        /// <summary>
        /// 添加UGUI侦听
        /// </summary>
        protected override void AddUGUIListener()
        {

        }

        /// <summary>
        /// 添加全局侦听（MsgDispatcher）
        /// </summary>
        protected override void AddMsgListeners()
        {

        }

        protected override void OnDispose()
        {
            this.mallItemCid = 0;
            this.CfgMallItem = null;
        }

        #region methonds

        public void Show(int mallItemCid)
        {
            this.mallItemCid = mallItemCid;
            this.CfgMallItem = TableCenter.mallItem.Get(this.mallItemCid);
            if (this.CfgMallItem == null) return;
            this.Show();

            this.SetRawImageTexture(this.ui.rawIcon, this.CfgMallItem.BG_fullPath);
            this.ui.textName.text = this.CfgMallItem.Name;
            this.ui.textDesc.text = this.CfgMallItem.Desc;
            this.ui.textPriceTitle.text = APIMall.RechargeTitle;
            this.ui.textPriceValue.text = this.CfgMallItem.Amount.ToString();
            this.ShowFirstReward();
        }

        public void ShowFirstReward()
        {
            var isFirstRecharge = MallModule.Instance.IsFirstRecharge(this.mallItemCid);
            this.ui.first.SetActive(isFirstRecharge);
            if (isFirstRecharge)
            {
                this.ui.textFirstValue.text = this.CfgMallItem.BonusPaypoint.ToString();
                var cfg = TableCenter.item.Get(ItemConst.ItemCid_PayPoint_ForShow);
                this.SetImageSprite(this.ui.iconFirst, cfg.MoneyIcon_fullPath);
            }
        }

        #endregion methonds
    }
}
